package com.example.origin.alibaba.gateway.controller;

import com.delicacy.grape.alibaba.common.dto.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RefreshScope
@RestController
public class DemoController {
    @Value("${name:3333}")
    private String name;

    @GetMapping(value = "/echo/{string}")
    public String echo(@PathVariable String string) {
        return name+"："+"Hello Nacos Discovery " + string;
    }


    @GetMapping(value = "/getUser/{userId}")
    public User getUser(@PathVariable String userId) {
        User user = new User();
        user.setAge(11);
        user.setId(userId);
        user.setName(name);
        if (Objects.equals(userId, "1")){
            throw new RuntimeException();
        }
        return user;
    }
}
